"""
ASGI config for application project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
"""

import os  # 导入os模块，用于设置环境变量

from django.core.asgi import get_asgi_application  # 从django.core.asgi模块导入get_asgi_application函数
from channels.auth import AuthMiddlewareStack  # 从channels.auth模块导入AuthMiddlewareStack类
from channels.routing import ProtocolTypeRouter, URLRouter  # 从channels.routing模块导入ProtocolTypeRouter和URLRouter类

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'application.settings')  # 设置环境变量，指定Django的settings模块
os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"  # 设置环境变量，允许异步操作

http_application = get_asgi_application()  # 获取ASGI应用实例
from application.routing import websocket_urlpatterns  # 从application.routing模块导入websocket_urlpatterns变量

application = ProtocolTypeRouter({  # 创建一个ProtocolTypeRouter实例
    "http": http_application,  # 将HTTP协议映射到http_application
    'websocket': AuthMiddlewareStack(  # 将WebSocket协议映射到AuthMiddlewareStack实例
        URLRouter(  # 创建一个URLRouter实例
            websocket_urlpatterns  # 指明路由文件是devops/routing.py
        )
    ),
})

